/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.notaria.guerrasalas.be;

import java.io.Serializable;
import javax.persistence.Basic;
import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import javax.persistence.Transient;

/**
 *
 * @author Administrador
 */
@Entity
@Table(name = "SERVICIO_TICKET")
public class ServicioTicket implements Serializable {

    private static final long serialVersionUID = 1L;
    @EmbeddedId
    protected ServicioTicketPK servicioTicketPK;
    @Basic(optional = false)
    @Column(name = "CANTIDAD", nullable = false)
    private Integer cantidad = 0;
    @Basic(optional = false)
    @Column(name = "PRECIO", nullable = false, precision = 19, scale = 4)
    private Double precio = 0.0;
    @JoinColumn(name = "FID_SERVICIO", referencedColumnName = "ID_SERVICIO", nullable = false, insertable = true, updatable = true)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Servicio servicio;
    @JoinColumn(name = "FID_TICKET", referencedColumnName = "ID_TICKET", nullable = false, insertable = true, updatable = true)
    @ManyToOne(optional = false, fetch = FetchType.LAZY)
    private Ticket ticket;
    @Transient
    private boolean seleccionado;

    public ServicioTicket() {
        this.servicioTicketPK = new ServicioTicketPK();
    }

    public ServicioTicket(long fidTicket, long fidServicio) {
        this.servicioTicketPK = new ServicioTicketPK(fidTicket, fidServicio);
    }

    public ServicioTicketPK getServicioTicketPK() {
        return servicioTicketPK;
    }

    public void setServicioTicketPK(ServicioTicketPK servicioTicketPK) {
        this.servicioTicketPK = servicioTicketPK;
    }

    public Integer getCantidad() {
        return cantidad;
    }

    public void setCantidad(Integer cantidad) {
        this.cantidad = cantidad;
    }

    public Double getPrecio() {
        return precio;
    }

    public void setPrecio(Double precio) {
        this.precio = precio;
    }

    public Double getImporte() {
        return precio * cantidad;
    }

    public Servicio getServicio() {
        return servicio;
    }

    public void setServicio(Servicio servicio) {
        this.servicio = servicio;
        this.servicioTicketPK.setIdServicio(servicio.getIdServicio());
    }

    public Ticket getTicket() {
        return ticket;
    }

    public void setTicket(Ticket ticket) {
        this.ticket = ticket;
        this.servicioTicketPK.setIdServicio(ticket.getIdTicket());
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (servicioTicketPK != null ? servicioTicketPK.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ServicioTicket)) {
            return false;
        }
        ServicioTicket other = (ServicioTicket) object;
        if ((this.servicioTicketPK == null && other.servicioTicketPK != null) || (this.servicioTicketPK != null && !this.servicioTicketPK.equals(other.servicioTicketPK))) {
            return false;
        }
        return true;
    }

    public boolean isEliminable(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final ServicioTicket other = (ServicioTicket) obj;
        if (this.servicioTicketPK != other.servicioTicketPK && (this.servicioTicketPK == null || !this.servicioTicketPK.equals(other.servicioTicketPK))) {
            return false;
        }
        if (this.cantidad != other.cantidad && (this.cantidad == null || !this.cantidad.equals(other.cantidad))) {
            return false;
        }
        if (this.precio != other.precio && (this.precio == null || !this.precio.equals(other.precio))) {
            return false;
        }
        if (this.servicio != other.servicio && (this.servicio == null || !this.servicio.equals(other.servicio))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return servicioTicketPK.toString();
    }

    public boolean isSeleccionado() {
        return seleccionado;
    }

    public void setSeleccionado(boolean seleccionado) {
        this.seleccionado = seleccionado;
    }
}
